import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from "../components/Login"
// import Login2 from "../components/Login2"

import Main from "../components/Main"
// import Index from "../components/Index/Index.vue"
import CompanyIndex from "../components/Company/Index.vue"
import BankinfoIndex from "../components/Bankinfo/Index.vue"
import ProjectIndex from "../components/Project/Index.vue"
import SupplierIndex from "../components/Supplier/Index.vue"
import ExpenditureIndex from "../components/Expenditure/Index.vue"
import SetUpIndex from "../components/SetUp/Index.vue"
import InvoiceIndex from "../components/Invoice/Index.vue"

Vue.use(VueRouter)
var router = new VueRouter({
  routes: [
    { path: '/', redirect: '/Login' },
    // { path: '/Login', component: Login2 },
    { path: '/Login', component: Login },
    { path: '/Main', component: Main },
    // { path: '/Index', component: Index },//主页
    { path: '/CompanyIndex', component: CompanyIndex },
    { path: '/BankinfoIndex', component: BankinfoIndex },
    { path: '/ProjectIndex', component: ProjectIndex },
    { path: '/SupplierIndex', component: SupplierIndex },
    { path: '/ExpenditureIndex', component: ExpenditureIndex },
    { path: '/SetUpIndex', component: SetUpIndex },
    { path: '/InvoiceIndex', component: InvoiceIndex },
  ]
})
router.beforeResolve((to, from, next) => {
  //to将要访问的路径
  // from 代表从那个路径调转
  //next  放行
  if (to.path === '/Login') return next();
  var token = window.sessionStorage.getItem('token');
  if (token == '' || token == undefined) {
    return next('/Login');
  }
  next();
})
export default router
